import random

import requests
#获取验证码
from ddddocr import DdddOcr

ocr = DdddOcr(show_ad=False)

url_img = f"https://www.labnetwork.com.cn/gateway/basic/mall/oauth/code?{random.Random()}"

res_img = requests.get(url_img)


uuid = res_img.json()['data']['uuid']
base64_img = res_img.json()['data']['img'].split(',')[1:][0]

r = ocr.classification(base64_img)

#发起登录请求
json_login = {
    "userEmail": "2745358307@qq.com",
    "password": "Hbg123666",
    "captchaCode": f"{r}",
    "captchaKey": f"{uuid}"
}
url_login = "https://www.labnetwork.com.cn/gateway/basic/mall/oauth/login"

res_login = requests.post(url_login,json=json_login)

print(res_login.json())

token = res_login.json()['data']['userInfo']["token"]
print(token)

#获取分页参数

url_page = "https://www.labnetwork.com.cn/gateway/oldapi/mall/chemical/products"
json = {
    "lnIdList": [
        "LN05341162",
        "LN00110439",
        "LN01348271",
        "LN00178782",
        "LN01746886",
        "LN03203422",
        "LN03294497",
        "LN01871650",
        "LN05091255",
        "LN02033597"
    ],
    "pageSize": 10,
    "startRecord": 0,
    "country": "CN"}
headers = {
    "token":f"{token}1"
}
res_page = requests.post(url_page,json=json,headers=headers)
print(res_page.json())
